package utils

import (
	"os"
	"path/filepath"
	"strings"
)

func FindFilesByType(rootPath string, fileType string, isFullPath bool) ([]string, error) {
	var matchedFiles []string

	err := filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.IsDir() && strings.HasSuffix(info.Name(), fileType) {
			if isFullPath {
				matchedFiles = append(matchedFiles, path)
			} else {
				matchedFiles = append(matchedFiles, info.Name())
			}
		}
		return nil
	})

	if err != nil {
		return nil, err
	}

	return matchedFiles, nil
}
